package com.example.minefieldkeepercloud.network;

import android.util.Log;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017/7/25.
 * 新房网络接口辅助类
 */

public class NetHelperNew {
//    public static final String URL = "http://btcc.ren:8070/";//IP地址
    public  static   String URL = "http://btcc.ren:8070/";//IP地址
    private static final String LOGIN = "API/AppBaseInfoAccess/ttGetLgonSysUser";//用户登录
    private static final String GetFactoryUserInFo = "/API/AppBaseInfoAccess/ttGetFactoryUserInFo";//员工列表
    private static final String GetFactoryByCustomerId = "/API/AppBaseInfoAccess/ttGetFactoryByCustomerId";//矿场列表
    private static final String GetCalPoweStatistics_Chart_Day = "/API/AppMachineAccess/ttCalPoweStatistics_Chart_Day";//矿机算力统计-曲线图-日
    private static final String ttCalPoweStatistics_Chart_Month = "/API/AppMachineAccess/ttCalPoweStatistics_Chart_Month";//矿机算力统计-曲线图-月
    private static final String ttCalPoweStatistics_Table_Day = "/API/AppMachineAccess/ttCalPoweStatistics_Table_Day";//矿机算力统计-表-日接口
    private static final String ttCalPoweStatistics_Table_Month = "/API/AppMachineAccess/ttCalPoweStatistics_Table_Month";//矿机算力统计-表-月接口
    private static final String GetFactory = "/API/AppBaseInfoAccess/ttGetFactory";//获取矿场列表接口
    private static final String GetCalPoweStatistics_Table = "/API/AppMachineAccess/ttRSL_CalPoweStatistics_Table";//矿机日算力统计表
    private static final String GetTGByFactoryID = "/API/AppBaseInfoAccess/ttGetTGByFactoryID";//根据矿场id获取托管列表接口
    private static final String GetCalPoweStatistics_Detail_Table = "/API/AppMachineAccess/ttRSL_CalPoweStatistics_Detail_Table";//日算力统计-表-详细
    private static final String GetErrInfoStatistics_Table = "/API/AppMachineAccess/ttErrInfoStatistics_Table";//矿机维护统计-表
    private static final String GetErrInfoStatistics_Detail_Table = "/API/AppMachineAccess/ttErrInfoStatistics_Detail_Table";//矿机维护统计-表详细-接口
    private static final String GetErrInfoStatistics_Chart = "/API/AppMachineAccess/ttErrInfoStatistics_Chart";//矿机维护统计-图-接口
    private static final String Re_statistics = "/API/AppMachineAccess/ttRe_statistics_new";//重启统计
    private static final String GetVersionr = "/API/AppBaseInfoAccess/ttGetVersion";//版本更新

    private static final String GetOre_Machine = "/API/AppMachineAccess/ttOre_Machine_new";//待处理矿机-接口

    private static final String WhiteOrderList = "http://btcc.ren:8070/api/AppSystemAccess/WhiteOrderList";//常用矿池列表
    private static final String WhiteOrder = "http://btcc.ren:8070/api/AppSystemAccess/WhiteOrder";//常用矿池详情
    private static final String SetPool = "http://btcc.ren:8070/api/AppSystemAccess/SetPool";//矿池设置

    private static final String ttGetFactory_New = "/api/AppBaseInfoAccess/ttGetFactory_New";//运维获取矿场下拉列表（根据登录用户）

    private static final String ttGetBrandlAndModel = "/api/AppBaseInfoAccess/ttGetBrandlAndModel";//矿机品牌和机型统一返回
    private static final String ttGetTGByFactory = "/api/AppBaseInfoAccess/ttGetTGByFactory";//加载托管用户（根据矿场id）

    private static final String ttGetCurrency = "/api/AppBaseInfoAccess/ttGetCurrency";//币种接口

    private static final String ttMachineMonitorScan_List = "/api/AppMachineAccess/ttMachineMonitorScan_List";//矿机维护列表接口
    private static final String ttGetYHByFactory = "/api/AppMachineAccess/ttGetYHByFactory";//加载用户（根据矿场id）接口

    private static final String ttUpdateMachineErrInfoFix = "/api/AppMachineAccess/ttUpdateMachineErrInfoFix";//矿机维护维修保存接口

    private static final String ttGetCQ_SX_Insert = "/api/AppMachineAccess/ttGetCQ_SX_Insert";//矿机维护刷新重启添加接口（第一次访问）
    private static final String ttGetCQ_SX_Loop = "/api/AppMachineAccess/ttGetCQ_SX_Loop";//矿机维护刷新重启持续访问接口（持续访问）
    private static final String GetMacErrorList = "/api/AppMachineAccess/tt_APP_GetMacErrorList";//矿机维修列表接口
    private static final String GetMacError_Update = "/api/AppMachineAccess/tt_APP_GetMacError_Update";//返修上架操作
    /**
     * 登录接口
     *
     * @param LoginName
     * @param LoginPass
     * @param callback
     */
    public static void login(String LoginName, String LoginPass, HttpUtils.HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("LoginName", LoginName);
        map.put("LoginPass", LoginPass);
        String json = MyGson.getInstance().toJson(map);

      //if(LoginName.equals("13800000000")||LoginName.equals("13940129152")||LoginName.equals("13060440268")||LoginName.equals("13998105810"))
//        ||LoginName.equals("13998105810")||LoginName.equals("13998105819")
        if(LoginName.equals("13800000000")||LoginName.equals("13998105819"))
            URL="http://btcc.ren:8060/";
        else
            URL="http://btcc.ren:8070/";
        new HttpUtils().postNewLoginJson(URL + LOGIN, json, callback);
    }


    /**
     * 员工列表
     *
     * @param callback
     */
    public static void GetFactoryUserInFo(HttpUtils.HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
//        map.put("CurrencyCode", CurrencyCode);
        String json = MyGson.getInstance().toJson(map);
        new HttpUtils().postNewJson(URL + GetFactoryUserInFo, json, callback);
    }

    /**
     * 基础信息矿场列表
     *
     * @param callback
     */
    public static void GetFactoryByCustomerId(HttpUtils.HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("ID", "19");
        String json = MyGson.getInstance().toJson(map);
        new HttpUtils().postNewJson(URL + GetFactoryByCustomerId, json, callback);
    }

    /**
     * 矿机算力统计-曲线图-日
     *
     * @param datetype 0 日 1月
     * @param Factory  矿场ID
     * @param Time     统计时间
     * @param callback
     */
    public static void GetCalPoweStatistics_Chart_Day(int datetype, String Factory, String Time, HttpUtils.HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("Factory", Factory);

        if (datetype == 0) {
            map.put("Time", Time);
            String json = MyGson.getInstance().toJson(map);
            Log.i("Json", json);
            new HttpUtils().postNewJson(URL + GetCalPoweStatistics_Chart_Day, json, callback);
        } else if (datetype == 1) {
            map.put("Month", Time);
            String json = MyGson.getInstance().toJson(map);
            Log.i("Json", json);
            new HttpUtils().postNewJson(URL + ttCalPoweStatistics_Chart_Month, json, callback);
        }

    }

    /**
     * 矿机算力统计-表
     *
     * @param datetype 0 日 1月
     * @param Factory  矿场ID
     * @param Time     统计时间
     * @param callback
     */
    public static void ttCalPoweStatistics_Table_Day(int datetype, String Factory, String Time, HttpUtils.HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("Factory", Factory);

        if (datetype == 0) {
            map.put("Time", Time);
            String json = MyGson.getInstance().toJson(map);
            Log.i("Json", json);
            new HttpUtils().postNewJson(URL + ttCalPoweStatistics_Table_Day, json, callback);
        } else if (datetype == 1) {
            map.put("Month", Time);
            String json = MyGson.getInstance().toJson(map);
            Log.i("Json", json);
            new HttpUtils().postNewJson(URL + ttCalPoweStatistics_Table_Month, json, callback);
        }

    }

    /**
     * 获取矿场接口
     *
     * @param callback
     */
    public static void GetFactory(HttpUtils.HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        String json = MyGson.getInstance().toJson(map);
        Log.d("XXXXXX",URL);
        new HttpUtils().postNewJson(URL + GetFactory, json, callback);
    }

    /**
     * 获取矿机日算力统计表
     * @param Factory
     * @param cmbTG
     * @param bzl
     * @param time_vale
     * @param callback
     */
    public static void GetCalPoweStatistics_Table(String Factory, String cmbTG, String bzl, String time_vale, HttpUtils.HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("Factory", Factory);
        map.put("cmbTG", cmbTG);
        map.put("bzl", bzl);
        map.put("time_vale", time_vale);
        map.put("timetype", "0");
        String json = MyGson.getInstance().toJson(map);
        new HttpUtils().postNewJson(URL + GetCalPoweStatistics_Table, json, callback);
    }

    /**
     * 根据矿场id获取托管列表接口
     *
     * @param Factory
     * @param callback
     */
    public static void GetTGByFactoryID(String Factory, HttpUtils.HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("Factory", Factory);
        String json = MyGson.getInstance().toJson(map);
        new HttpUtils().postNewJson(URL + GetTGByFactoryID, json, callback);
    }

    /**
     * 日算力统计详情
     *
     * @param factoryID
     * @param userID
     * @param bzl
     * @param time_vale
     * @param callback
     */
    public static void GetCalPoweStatistics_Detail_Table(String factoryID, String userID, String bzl, String time_vale, HttpUtils.HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("factoryID", factoryID);
        map.put("userID", userID);
        map.put("bzl", bzl.substring(0, bzl.length() - 1));
        map.put("time_vale", time_vale);
        map.put("timetype", "0");
        String json = MyGson.getInstance().toJson(map);
        Log.d("====", json);
        new HttpUtils().postNewJson(URL + GetCalPoweStatistics_Detail_Table, json, callback);
    }

    /**
     * 矿机维护统计-表-接口
     *
     * @param factoryID
     * @param Month
     * @param callback
     */
    public static void GetErrInfoStatistics_Table(String factoryID, String Month, HttpUtils.HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("factoryID", factoryID);
        map.put("Month", Month);
        String json = MyGson.getInstance().toJson(map);
        new HttpUtils().postNewJson(URL + GetErrInfoStatistics_Table, json, callback);
    }

    /**
     * 矿机维护统计-表详细-接口
     *
     * @param factoryID
     * @param userID
     * @param Month
     * @param type
     * @param callback
     */
    public static void GetErrInfoStatistics_Detail_Table(String factoryID, String userID, String Month, String type, HttpUtils.HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("factoryID", factoryID);
        map.put("userID", userID);
        map.put("Month", Month);
        map.put("type", type);
        String json = MyGson.getInstance().toJson(map);
        new HttpUtils().postNewJson(URL + GetErrInfoStatistics_Detail_Table, json, callback);
    }

    /**
     * 矿机维护统计-图详细-接口
     *
     * @param factoryID
     * @param Month
     * @param callback
     */
    public static void GetErrInfoStatistics_Chart(String factoryID, String Month, HttpUtils.HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("factoryID", factoryID);
        map.put("Month", Month);
        String json = MyGson.getInstance().toJson(map);
        Log.d("xxxx",json);
        new HttpUtils().postNewJson(URL + GetErrInfoStatistics_Chart, json, callback);
    }

    /**
     * 待处理矿机
     * @param callback
     */
    public static void GetOre_Machine(String pageIndex,String type,HttpUtils.HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("type", type);
        map.put("pageIndex", pageIndex);
        map.put("pageSize", "10");
        String json = MyGson.getInstance().toJson(map);
        new HttpUtils().postNewJson(URL + GetOre_Machine, json, callback);
    }


    /**
     * 重启统计
     *
     * @param StartDate 开始时间
     * @param EndDate
     * @param callback
     */
    public static void GetRe_statistics(String pageIndex,String StartDate, String EndDate, HttpUtils.HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("StartDate", StartDate);
        map.put("EndDate", EndDate);
        map.put("pageIndex", pageIndex);
        map.put("pageSize", "10");
        String json = MyGson.getInstance().toJson(map);
        Log.i("Json", json);

        new HttpUtils().postNewJson(URL + Re_statistics, json, callback);


    }

    /**
     * 版本更新
     * @param callback
     */
    public static void GetVersionr(HttpUtils.HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("fileType", "4");
        String json = MyGson.getInstance().toJson(map);
        Log.i("Json", json);
       new HttpUtils().postNewJson(URL + GetVersionr, json, callback);


    }

    /**
     * 常用矿池列表
     * @param pageIndex
     * @param
     * @param callback
     */
    public static void GetWhiteOrderList(String pageIndex,HttpUtils.HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("pageIndex", pageIndex);
        map.put("pageSize", "10");
        String json = MyGson.getInstance().toJson(map);
        new HttpUtils().postNewJson(WhiteOrderList, json, callback);
    }

    /**
     * 常用矿池详情
     * @param Id
     * @param callback
     */
    public static void GetWhiteOrder(String Id,HttpUtils.HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("Id", Id);
        String json = MyGson.getInstance().toJson(map);
        new HttpUtils().postNewJson(WhiteOrder, json, callback);
    }

    /**
     * 矿池设置
     * @param ttkh
     * @param factoryId
     * @param smsSwitch
     * @param phone
     * @param ltPool
     * @param callback
     */
    public static void SetPool(String ttkh, String factoryId, String smsSwitch, String phone, JSONObject ltPool, HttpUtils.HttpCallback callback) {
//        Map<String, Object> map = new HashMap<>();
//        map.put("ttkh", ttkh);
//        map.put("factoryId", factoryId);
//        map.put("smsSwitch", smsSwitch);
//        map.put("phone", phone);
//        map.put("ltPool", ltPool);
//        String json = MyGson.getInstance().toJson(map);
//        Log.d("XXXX",json);
//        new HttpUtils().postNewJson(SetPool, json, callback);

        JSONObject obj = new JSONObject();
        try {
            obj.put("ttkh", ttkh);
            obj.put("factoryId", factoryId);
            obj.put("smsSwitch", smsSwitch);
            obj.put("phone", phone);
            obj.put("ltPool", ltPool);
        } catch (Exception e) {
        }
        Log.d("XXXX", obj.toString());
        new HttpUtils().postNewJson(SetPool,  obj.toString(), callback);
    }

    /**
     * 运维 获取矿场下拉列表（根据登录用户）
     * @param callback
     */
    public static void GetttGetFactory_New(HttpUtils.HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        String json = MyGson.getInstance().toJson(map);
        Log.d("XXXXXX",URL);
        new HttpUtils().postNewJson(URL + ttGetFactory_New, json, callback);
    }

    /**
     * 矿机品牌和机型统一返回接口
     * @param callback
     */
    public static void GetBrandlAndModel(HttpUtils.HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        String json = MyGson.getInstance().toJson(map);
        new HttpUtils().postNewJson(URL + ttGetBrandlAndModel, json, callback);
    }

    /**
     * 加载托管用户（根据矿场id）接口
     * @param Factory
     * @param callback
     */
    public static void GetTGByFactory(String Factory,HttpUtils.HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("Factory", Factory);
        String json = MyGson.getInstance().toJson(map);
        new HttpUtils().postNewJson(URL+ttGetTGByFactory, json, callback);
    }

    /**
     * 币种接口
     * @param callback
     */
    public static void GetCurrency(HttpUtils.HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        String json = MyGson.getInstance().toJson(map);
        new HttpUtils().postNewJson(URL + ttGetCurrency, json, callback);
    }

    /**
     * 矿机维护列表接口
     * @param ZT
     * @param factoryID
     * @param IPS
     * @param IPE
     * @param BrandlID
     * @param ModelID
     * @param BZID
     * @param WDmin
     * @param WDmax
     * @param SLmin
     * @param SLmax
     * @param userID
     * @param pageIndex
     * @param
     * @param callback
     */
    public static void MachineMonitorScan_List(String Sort,String ZT,String factoryID,String IPS,String IPE,String BrandlID,String  ModelID,
                                               String BZID,String WDmin,String WDmax,String SLmin,String SLmax,String userID,
                                               String pageIndex,HttpUtils.HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("Sort", Sort);
        map.put("ZT", ZT);
        map.put("factoryID", factoryID);
        map.put("IPS", IPS);
        map.put("IPE", IPE);
        map.put("BrandlID", BrandlID);
        map.put("ModelID", ModelID);
        map.put("BZID", BZID);
        map.put("WDmin", WDmin);
        map.put("WDmax", WDmax);
        map.put("SLmin", SLmin);
        map.put("SLmax", SLmax);
        map.put("userID", userID);
        map.put("pageIndex", pageIndex);
        map.put("pageSize", "20");
        String json = MyGson.getInstance().toJson(map);
        Log.d("xxxxxxx",json);
        new HttpUtils().postNewJson(URL+ttMachineMonitorScan_List, json, callback);
    }

    /**
     * 加载用户（根据矿场id）接口
     * @param Factory
     * @param callback
     */
    public static void GetYHByFactory(String Factory,HttpUtils.HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("Factory", Factory);
        String json = MyGson.getInstance().toJson(map);
        new HttpUtils().postNewJson(URL+ttGetYHByFactory, json, callback);
    }

    /**
     * 矿机维护维修保存接口
     * @param HandleMethod
     * @param factoryID
     * @param IP
     * @param MachineName1
     * @param UserID
     * @param FullName
     * @param Remark
     * @param callback
     */
    public static void UpdateMachineErrInfoFix(String HandleMethod,String factoryID,String IP,String MachineName1,String UserID,
                                               String FullName,String Remark,String TimeNow,HttpUtils.HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("HandleMethod", HandleMethod);
        map.put("factoryID", factoryID);
        map.put("IP", IP);
        map.put("MachineName1", MachineName1);
        map.put("UserID", UserID);
        map.put("FullName", FullName);
        map.put("Remark", Remark);
        map.put("TimeNow", TimeNow);
        String json = MyGson.getInstance().toJson(map);
        Log.d("xxxxx",json);
        new HttpUtils().postNewJson(URL+ttUpdateMachineErrInfoFix, json, callback);
    }

    /**
     * 矿机维护刷新重启添加接口（第一次访问）
     * @param factoryID
     * @param IP
     * @param ControlOrder
     * @param callback
     */
    public static void GetCQ_SX_Insert(String factoryID,String IP,String ControlOrder,HttpUtils.HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("factoryID", factoryID);
        map.put("IP", IP);
        map.put("ControlOrder", ControlOrder);
        String json = MyGson.getInstance().toJson(map);
        Log.d("cqcqcq",json);
        new HttpUtils().postNewJson(URL+ttGetCQ_SX_Insert, json, callback);
    }

    /**
     * 矿机维护刷新重启持续访问接口（持续访问）
     * @param ID
     * @param callback
     */
    public static void GetCQ_SX_Loop(String ID,String XXID,String BZID,HttpUtils.HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("ID", ID);
        map.put("XXID", XXID);
        map.put("BZID", BZID);
        String json = MyGson.getInstance().toJson(map);
        Log.d("cqcqcq2222",json);
        new HttpUtils().postNewJson(URL+ttGetCQ_SX_Loop, json, callback);
    }


    /**
     * 矿机维修列表接口
     * @param Sort 默认传：“4”（2：时间正序 3：时间倒叙 4：ip正序 5：ip倒叙）
     * @param ZT 	0：”全部” 3：”维修” 6：”维护”
     * @param factoryID 矿场id
     * @param IPS ip段开始：198.1.1.1
     * @param IPE ip段开始：198.1.1.100
     * @param BrandlID 品牌id
     * @param ModelID 机型id:100,1223,1234（字符串）
     * @param userID 托管用户:10,12,13（字符串）
     * @param pageIndex
     * @param callback
     */
    public static void GetMacErrorList(String Sort,String ZT,String factoryID,String IPS,String IPE,String BrandlID,String  ModelID,String userID,
                                               String pageIndex,HttpUtils.HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("Sort", Sort);
        map.put("ZT", ZT);
        map.put("factoryID", factoryID);
        map.put("IPS", IPS);
        map.put("IPE", IPE);
        map.put("BrandlID", BrandlID);
        map.put("ModelID", ModelID);
        map.put("userID", userID);
        map.put("pageIndex", pageIndex);
        map.put("pageSize", "20");
        String json = MyGson.getInstance().toJson(map);
        Log.d("-->",URL+GetMacErrorList);
        Log.d("-->",json);
        new HttpUtils().postNewJson(URL+GetMacErrorList, json, callback);
    }

    /**
     * 返修上架操作
     * @param Flag 处理方法：返修 7， 上架 1
     * @param factoryID 矿场id
     * @param ID
     * @param SerialNumber 序列号
     * @param callback
     */
    public static void GetMacError_Update(String Flag,String factoryID,String ID,String SerialNumber,HttpUtils.HttpCallback callback) {
        Map<String, String> map = new HashMap<>();
        map.put("Flag", Flag);
        map.put("factoryID", factoryID);
        map.put("ID", ID);
        map.put("SerialNumber", SerialNumber);
        String json = MyGson.getInstance().toJson(map);
        Log.i("Json", json);
        new HttpUtils().postNewJson(URL+GetMacError_Update, json, callback);
    }
}
